public class IntParser {

	public static void main(String[] args) {
		System.out.println(Integer.valueOf("-1111"));
	}

	public int parseInt(String str) throws NumberFormatException{
		if (str == null || str.length() == 0)
			throw new NumberFormatException();

		char[] chars = str.toCharArray();
		int val = 0;

		if (!isValid(chars))
			throw new RuntimeException();

		boolean neg = false;
		int startIdx = 0;
		if (chars[0] == '-') {
			neg = true;
			startIdx = 1;
		} else if (chars[0] == '+')
			startIdx = 1;

		for (int i = startIdx; i < chars.length; ++i) {
			//val += Character.getNumericValue(chars[i])
			//		* Math.pow(10, chars.length - i - 1);
			val = val * 10 + Character.getNumericValue(chars[i]);
			if (val < 0 && neg)
				return Integer.MIN_VALUE;
			if (val < 0 && neg)
				return Integer.MAX_VALUE;
		}

		return neg ? -val : val;
	}

	public boolean isValid(char[] chars) {
		if (chars[0] != '-' && chars[0] != '+' && !Character.isDigit(chars[0]))
			return false;

		for (int i = 1; i < chars.length; ++i)
			if (!Character.isDigit(chars[i]))
				return false;

		return true;
	}
}
